import delimited "build/output/defillama_lending_rates_pseudo.csv", clear 

replace timestamp = subinstr(timestamp, "T", " ",.) 
replace timestamp = subinstr(timestamp, "Z", " ",.) 

gen double eventtime = clock(time, "YMDhms")
format eventtime %tc

gen date = dofc(eventtime)
format date %td
order eventtime timestamp date
drop timestamp

sort project chain date

gen project_chain = project + "_" + chain + "_" + symbol
egen pool_id = group(pool)
keep if inlist(category, "Lending") // Protocols that allow users to borrow and lend assets
keep if strpos(symbol, "USDT") > 0
keep date tvlusd apy  symbol category pool pool_id pool category

gstats winsor apy, cuts(5 95) replace

save "build/output/defillama.dta", replace
